Repository navigation
Fix Windows focus stealing from agent foreground-process scan (hide conhost window) - #8053
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughWindows foreground process enumeration now passes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
16ab295 to
87fbc0d
Compare
Agent foreground-process inspection re-forks powershell.exe (or the wmic fallback) to detect which agent runs in each terminal. Both spawns omitted windowsHide, so on Windows each fork popped a fresh conhost console window that flashed and stole keyboard focus from the foreground app — including Orca's own terminal — recurring roughly once every few tens of seconds while an agent session was open (and more often under continuous agent output). Add windowsHide: true to both probes (matching the codebase-wide convention) plus a regression test asserting the spawn options. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
87fbc0d to
4b7376d
Compare
Jinwoo-H
left a comment
There was a problem hiding this comment.
Thanks for tracking this down. Reviewed and validated on Windows:
- Both PowerShell and WMIC scans now suppress their console windows.
- Updated the regression fixtures for compatibility with current main.
- Typecheck, lint, and focused tests pass against current main.
- Live Electron validation observed 9 real scans with no visible scan window or focus loss.
|
Thanks for the review! |
…onhost window) (stablyai#8053) * Hide console window for Windows agent foreground-process scan Agent foreground-process inspection re-forks powershell.exe (or the wmic fallback) to detect which agent runs in each terminal. Both spawns omitted windowsHide, so on Windows each fork popped a fresh conhost console window that flashed and stole keyboard focus from the foreground app — including Orca's own terminal — recurring roughly once every few tens of seconds while an agent session was open (and more often under continuous agent output). Add windowsHide: true to both probes (matching the codebase-wide convention) plus a regression test asserting the spawn options. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * test(windows): include scan root in foreground fixtures --------- Co-authored-by: xucongwei <xucongwei@bytedance.com> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Co-authored-by: Jinwoo Hong <73622457+Jinwoo-H@users.noreply.github.com>
Summary
On Windows, Orca steals keyboard focus from whatever window the user is typing in while an agent session is open — the caret silently drops out of the focused input (the mouse pointer does not move), so keystrokes are lost until the user clicks back in. It happens to any foreground app (editors, browsers, chat, other terminals) and even to Orca's own terminal panes.
Severity — high impact. In practice the focus is stolen roughly once every few tens of seconds for the whole time an agent is running (the underlying scan can fire more often under heavy agent output). Even at that rate it is a serious, recurring interruption: it repeatedly yanks you out of whatever you are typing, all day, for anyone who keeps Orca open while running agents. Multiple users are affected, and the disruption disappears the moment Orca is closed — so we'd really appreciate an expedited review/merge.
Root cause
Agent foreground-process inspection (
windows-foreground-process-rows.ts) re-forkspowershell.exe— or thewmicfallback — to detect which agent is running in each terminal. Both spawns omittedwindowsHide. Electron's main process has no attached console, so Windows creates a fresh visible conhost window for each console child; it flashes for a few tens of milliseconds and vanishes, but that is long enough to grab the foreground and steal keyboard focus from the active window.The scan runs on a per-pane poll cadence (750ms active / 2000ms), but is gated down by relaxed retry tiers (~5s after recent PTY output, ~15s when idle) and a 500ms shared-snapshot dedup, so a fresh fork/flash does not happen every second — in normal use it lands roughly once every few tens of seconds, matching the observed symptom, and more often only while an agent is streaming continuous output.
Every other Windows spawn in the codebase already sets
windowsHide: true(git runner, rate-limit fetchers, account services, port scanner, …) — these two probes were the only ones missing it. Same class of bug reported against other agent tools: anthropics/claude-code#40334 and aaif-goose/goose#6701.Note: a related Windows 11 24H2 (build 26100) TSF/MSCTFIME focus regression can cause similar symptoms independently of Orca, but the recurring theft during agent use is squarely this scan.
Fix
Add
windowsHide: trueto both the PowerShell and wmic process-table probes. Purely a window-visibility flag — args, stdout capture, and parsing are unchanged; it only suppresses the console window that should never have appeared.Screenshots
No visual change (the fix removes an unwanted flashing console window; there is no in-app UI change to screenshot).
Testing
pnpm lintpnpm typecheckpnpm testpnpm buildAdded
windows-foreground-process-rows.test.ts, which drivesqueryWindowsProcessDescendantsunder a mockedchild_processand asserts both the PowerShell path and the wmic fallback passwindowsHide: true(guards against a future regression re-introducing the flash).AI Review Report
Reviewed with an AI coding agent; passed with no changes required. Focus areas checked:
windowsHide: trueis a validExecFileOptionsfield; it changes only console-window visibility, not process args, stdout capture, or the JSON/value parsing that follows. Behavior ofqueryWindowsProcessesWithPowerShell->queryWindowsProcessesWithWmicfallback is unchanged.win32-gated (resolveAgentForegroundProcessroutes non-Windows to the POSIXpssnapshot, which is unaffected). No shortcuts, labels, or path handling are involved.windowsHideis a no-op on non-Windows platforms. No Electron main-window/focus APIs are touched.windowsHide: truepattern used by every other Windows spawn in the repo.vi.mock('child_process')pattern fromwindows-agent-foreground-process-scan-volume.test.tsand asserts the exact regression surface.Security Audit
Low risk. No new input handling, no new command execution surface, no auth/secrets/IPC/dependency changes. The
powershell.exe/wmicargument vectors are untouched (still fixed, non-interpolated argv). If anything this reduces a UI-integrity risk by eliminating an unexpected foreground window that hijacks user focus. No follow-up required.Notes
Windows-only behavior change. No config or migration needed. Users on the shipped release will pick this up in the next build; meanwhile the only workaround is closing Orca or reducing agent activity.
🤖 Generated with Claude Code